package Controllers;


import java.io.UnsupportedEncodingException;
import java.util.Properties;



import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.sun.org.apache.bcel.internal.generic.D2F;
//import com.adobe.acrobat.util.Session;

import Entity.User;

public class Notificator extends Authenticator
{

	public void sendEmail(User user,String message)
	{
		
	}
	public void sendSMS(User user,String message)
	{
		
	}
	 public static void sendEmailNotification(String emailAddress, String theEmailText)
     {
      
		 
		 
		 
		 
		 
		 final String username = "icmbraudesys@gmail.com";
			final String password = "ztwcgekwrnpafanm";
	 
			Properties props = new Properties();
			props.put("mail.smtp.auth", "true");
			props.put("mail.smtp.starttls.enable", "true");
			props.put("mail.smtp.host", "smtp.gmail.com");
			props.put("mail.smtp.port", "587");
			props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
			Session session = Session.getInstance(props,
			  new javax.mail.Authenticator() {
				protected PasswordAuthentication getPasswordAuthentication() {
					return new PasswordAuthentication(username, password);
				}
			  });
	 
			try {
	 
				Message message = new MimeMessage(session);
				message.setFrom(new InternetAddress("icmbraudesys@gmail.com"));
				message.setRecipients(Message.RecipientType.TO,
					InternetAddress.parse(emailAddress));
				message.setSubject("ICM - SYSTEM");
				message.setText(theEmailText);
	 
				Transport.send(message);
	 
				System.out.println("Done");
	 
			} catch (MessagingException e) {
				System.out.println("errror");
				throw new RuntimeException(e);
			}
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
             }
            
             
     	
	 
	 
	 public static void main(String[] args)
 	{	
 		//StartUp();for(int i=0 ; i<=3;i++)
			 Notificator.sendEmailNotification("whisrael@gmail.com","Wow");
 		 System.out.print("Send");
 	}
	 

	





}
	



